<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<head>
<meta charset="UTF-8">
<title>新教员注册 - 家教114</title>
<link rel="stylesheet" href="/GDZjiajiaowang/source/css/regist.css">
<link rel="stylesheet" href="/GDZjiajiaowang/source/css/loginMini.css">
<script src="/GDZjiajiaowang/source/js/jquery-2.2.4.min.js"
	type="text/javascript" charset="utf-8"></script>
<script src="/GDZjiajiaowang/source/js/jquery.md5.js"
	type="text/javascript" charset="utf-8"></script>
<script src="/GDZjiajiaowang/source/js/jquery.cookie.js"
	type="text/javascript" charset="utf-8"></script>
<script src="/GDZjiajiaowang/source/js/public.js"
	type="text/javascript" charset="utf-8"></script>
</head>

<body>
	<div id="header">
		<div class="top-login">
			<div class="container">
				<div class="logo pull-left">
					<a href="/GDZjiajiaowang/source/page/index.jsp" class="pull-left"><img
						src="/GDZjiajiaowang/source/img/logo.png" height="30" width="170"
						alt=""></a> <a href="javascript:void(0)" class="pull-right dl">欢迎注册</a>
					<div class="clear"></div>
				</div>
				<div class="return pull-right">
					<a href="/GDZjiajiaowang/source/page/index.jsp">返回首页</a>
				</div>
				<div class="clear"></div>
			</div>
		</div>
	</div>
	<div id="register-banner">
		<img src="/GDZjiajiaowang/source/img/beijing.png">
		<div class="inbanner">
			<div class="container">
				<div class="left-form pull-left">
					<div class="right-code pull-left">
						<div class="code">
							<img src="/GDZjiajiaowang/source/img/1111223.gif">
						</div>
						<p>扫描二维码</p>
						<p>关注微信公众号</p>
					</div>
					<div class="form pull-right">
						<h4>教员注册</h4>
						<form name="form1" method="post" id="form1">
							<div class="fg">
								<select id="teacher_type" name="teacher_type"
									style="border: 0;width: 97%;">
									<option value="2">教师</option>
									<option value="1" selected="selected">家长/学生</option>
								</select>
							</div>
							<div class="fg">
								<input type="text" id="uname" name="mobile" placeholder="手机号码"
									maxlength=11 value="18252710762"> <span id="phoneTip">手机号必须为11位数字</span>
							</div>

							<div class="yfg" id="hidepassword">
								<input type="password" id="pw1" name="pw1"
									placeholder="密码（长度不小于六位）" class="pass" value="123456"
									onkeyup=""> <a href="javascript:void(0)"
									onclick="showpassword()" style="padding-right: 10px;">显示</a>
							</div>
							<div class="yfg" style='display:none' id="showpassword">
								<input type="text" id="pw2" name="pw2" placeholder="密码（长度不小于六位）"
									class="pass" onkeyup="" value="123456"> <a
									href="javascript:void(0)" onclick="hidepassword()"
									style="padding-right: 10px;">隐藏</a>
							</div>
							<div id="pwdTest">
								<span>密码必须是6位或6位以上的字符串</span>
							</div>
							<div class="yfg">
								<input type="text" id="vcode" name="vcode" placeholder="安全码"><label
									for=""> <img src="/GDZjiajiaowang/img" id="yz"></label>
								<div class="clear"></div>
								<span><input type="hidden" id="hidden_name" value=2></span>
							</div>
							<div class="fg">
								<input type="text" style="width:46%" id="mobile_code"
									name="mobile_code" placeholder="验证码" class="password">
								<input type="button"
									style="width:110px;background:#50c645;color:#fff;position: absolute;top:0;right:0;"
									value="发送验证码" id="djs"> <span></span>
							</div>

							<button type="button" onclick="registerBtn(this)">注册</button>
						</form>
						<br /> <a id="loginNow_a">已有账号 直接登录</a>
						<div class="clear"></div>
					</div>

					<div class="clear"></div>
				</div>
			</div>
		</div>
	</div>
	<div id="footer">
		<div class="pfoot">
			<div class="container">
				<p>© 2005－2018版权所有：景德镇GDZ教育科技有限公司 | 沪ICP备09062748号-5</p>
			</div>
		</div>
	</div>

	<!--
    	作者：杨辉
    	时间：2017-10-25
    	描述：登录弹窗r部分，
    -->
	<%@include file="/source/page/parts/loginMini.jsp"%>
<!--
    	作者：吴金山
    	时间：2017-10-25
    	描述：登录js
    -->
<%@include file="/source/page/parts/login.jsp"%>




	<script type="text/javascript" charset="utf-8">
		// 	一些变量
		var phoneIsRight = 0;
		var pwdIsRight = 0;

		// 	手机验证码发动后button中的倒计时
		function sixtySeconds() {
			setInterval(function() {
				var secondes = $("#djs");
				var buttonTest = secondes.val();
				if ("发送验证码" == buttonTest) {
					buttonTest = 60;
				} else {
					buttonTest = parseInt(buttonTest);
					if(buttonTest==0){
						secondes.val("发送验证码");
						clearInterval();
					}
				}
				buttonTest = 0 + buttonTest - 1;
				secondes.val(buttonTest + "s").attr("numtest", Math.random());
				if (buttonTest == 0) {
					secondes.val("发送验证码");
					clearInterval();
				}
			}, 1000);
		}

		// 			注册触发事件
		function registerBtn(btn) {
			var type = $(btn).parent().find("#teacher_type").val();
			var phone = $(btn).parent().find("#uname").val();
			if (phoneIsRight == 0) {
				alert("请先输入正确的手机号")
				return false;
			}
			if (pwdIsRight == 0) {
				alert("请先输入正确的密码")
				return false;
			}
			var picCode = $("#vcode").val();
			if (picCode.length != 4) {
				alert("请先输入正确的图片验证码")
				return false;
			}
			var mobile_code = $(btn).parent().find("#mobile_code").val();
			if (mobile_code.length != 6) {
				alert("请先输入正确的短信验证码")
				return false;
			}
			var pwd = $(btn).parent().find("#pw1").val();
			pwd = phone + pwd + phone;
			var md5Pwd = $.md5(pwd);
			//alert(md5Pwd);
			var json = {
				"phone" : phone,
				"md5Pwd" : md5Pwd,
				"picCode" : picCode,
				"mobile_code" : mobile_code,
				"type" : type
			};
			$
					.ajax({
						type : "post",
						url : "/GDZjiajiaowang/RegisterServlet",
						data : json,
						dataType : "text",
						contentType : "application/x-www-form-urlencoded; charset=utf-8",
						success : function(data) {
							alert(data);
							if (1 == data) {
								if (confirm("学生（家长）用户注册成功，是否现在登录？")) {
									$("#loginNow_div").fadeIn();
								}

							} else if (2 == data) {
								if (confirm("教师用户注册成功，是否现在登录？")) {
									$("#loginNow_div").fadeIn();

								}
							} else {
								alert("注册失败");
							}
						}
					})
		}

		$(function() {

			var phoneIsUsed = 0;
			// 提示手机号验证的提示
			$("#djs").click(function() {
				if (phoneIsUsed == 0) {
					alert("请先输入手机号");
					return false;
				}

				var phoneNum = $("#uname").val();
				$.ajax({
					type : "post",
					url : "/GDZjiajiaowang/smsServlet",
					data : {
						"tel" : phoneNum,
						"op" : "send"
					},
					datatype : "json",
					success : function(data) {
						sixtySeconds();
						alert("验证码发送成功！")
					}
				})

			})

			// 			已有账号直接登录
			$("#loginNow_a").click(function() {
				$("#loginNow_div").fadeIn();
			})
			var tip = $("#phoneTip");
			tip.hide();
			// 			手机号验证是否已注册

			$("#uname").change(function() {
				var re = /^1[34578]{1}\d{9}$/
				if (!re.test($(this).val())) {
					phoneIsUsed = 0
					alert("请输入正确手机号");
					tip.show().text("请输入11位手机号码").css("color", "red");
					phoneIsRight = 0;
					return false;
				}
				if ($(this).val().length < 11) {
					tip.show().text("请输入11位手机号码").css("color", "red");
					phoneIsRight = 0;
				} else {
					tip.show();
					var phoneNum = $(this).val();
					$.ajax({
						type : "post",
						url : "/GDZjiajiaowang/PhoneTestServlet",
						data : 'phoneNum=' + phoneNum,
						datatype : 'json',
						success : function(bool) {
							if (bool == "1") {
								tip.css("color", "green").text("该号码可用");
								phoneIsUsed = 1;
								phoneIsRight = 1;
							} else {
								tip.text("该号码已被注册").css("color", "red");
								phoneIsUsed = 0;
								phoneIsRight = 0;
							}
						}
					})

				}

			});

		})

		$("#yz").click(function() {
			$.ajax({
				type : "post",
				url : "/GDZjiajiaowang/img",
				success : function() {
					$("#yz").attr("src", "/GDZjiajiaowang/img");
				}

			});

		})

		function hidezzc() {
			$("#popDiv").hide();
			$("#bg").hide();
		}

		function CheckValue(btn) {
			if ($("#teacher_type").val() == "") {
				alert("请选择教员类型！");
				return (false);
			}
			if ($("#uname").val() == "") {
				alert("手机号不能为空！");
				return (false);
			}
			if ($("#pw1").val() == "") {
				alert("密码不能少于6位！")
				return (false);
			}
			if ($("#pw1").val().length > 20) {
				alert("密码不能多于16位！")
				return (false);
			}
			$("#pw2").val("");
			var $btn = $(btn);
			$btn.text('注册中...').prop('disabled', true);
			$.ajax({
				url : "/member/signup2.php",
				type : "post",
				data : $('#form1').serialize(),
				success : function(data) {
					$btn.text('注册').prop('disabled', false);
					data = eval('(' + data + ')');
					if (data.status == 1) {
						alert(data.msg);
					}
					if (data.status == 2) {
						location.href = data.url;
					}
				},
				error : function() {
					$btn.text('注册').prop('disabled', false);
				}
			});
		}

		// 		function sendMsg() {
		// 			var mobile = $("#uname").val();
		// 			var code = $("#vcode").val();
		// 			if (code == null || code == '') {
		// 				alert("请输入安全码");
		// 				return false;
		// 			}
		// 			if (mobile == null || mobile == '') {
		// 				alert("请输入手机号");
		// 				return false;
		// 			}

		// 			$("#djs").removeAttr("onclick");
		// 			$("#djs").css("background", "#aaa");
		// 			$("#djs").val("发送中...");
		// 			$.ajax({
		// 				url : "/member/sendMessage.php",
		// 				type : "post",
		// 				data : "code=" + code + "&mobile=" + mobile,
		// 				success : function(data) {
		// 					if (data == 1) {
		// 						Countdown();
		// 						$("#djs").removeAttr("onclick");
		// 						$("#djs").css("background", "#aaa");
		// 						alert("发送成功");
		// 					} else {
		// 						$("#djs").attr("onclick", "sendMsg()");
		// 						$("#djs").val("重新发送");
		// 						$("#djs").css("background", "#50c645");
		// 						alert(data);
		// 						$("#img_code").attr("src", "/member/check_number.php");
		// 					}
		// 				}
		// 			})
		// 		}
		var timer = 60;

		// 		function Countdown() {
		// 			if (timer >= 1) {
		// 				timer -= 1;
		// 				setTimeout(function() {
		// 					$("#djs").val("重新发送(" + timer + ")");
		// 					Countdown();
		// 				}, 1000);
		// 			} else {
		// 				timer = 60;
		// 				$("#djs").val("重新发送");
		// 				$("#djs").css("background", "#50c645");
		// 				$("#djs").attr("onclick", "sendMsg();");
		// 			}
		// 		}
		// 		切换密码时的显示隐藏
		function showpassword() {
			$("#hidepassword").hide();
			var pwdNow = $("#hidepassword").find("#pw1").val();
			$("#showpassword").show().find("#pw2").val(pwdNow);
		}

		function hidepassword() {
			$("#showpassword").hide();
			var pwdNow = $("#showpassword").find("#pw2").val();
			$("#hidepassword").show().find("#pw1").val(pwdNow);

		}
		// 		更改密码时的验证（长度）

		$("#form1").find(".pass").change(function() {
			var pwd = $(this).val();
			if (pwd.length < 6) {
				$("#pwdTest").show();
				pwdIsRight = 0;
			} else {
				$("#pwdTest").fadeOut();
				pwdIsRight = 1;
			}

		})
		function changepw1pw2() {
			var value = $("#pw1").val();
			$("#pw2").val(value);
		}

		function changepw2pw1() {
			var value = $("#pw2").val();
			$("#pw1").val(value);
		}
	</script>
</body>

</html>